﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CarInfor.DAL;

namespace CarInfor.UI
{
    public partial class frmUsePropertySet : Form
    {
        public frmUsePropertySet()
        {
            InitializeComponent();
        }

        private void Bind()
        {
            this.txtName.Text = "";
            this.lstUseProperty.Items.Clear();
            CarUseProperty useProperty = new CarUseProperty();
            DataTable dt = useProperty.Query();
            foreach (DataRow row in dt.Rows)
            {
                this.lstUseProperty.Items.Add(row["使用性质名称"].ToString());
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            CarUseProperty useProperty = new CarUseProperty();
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                MessageHelper.ShowInfo("请输入使用性质名称！");
                return;
            }
            if (useProperty.Query(" CarUsePropertyName='" + this.txtName.Text.Trim() + "'").Rows.Count > 0)
            {
                MessageHelper.ShowInfo("该使用性质名称名称已经存在！");
                return;
            }
            useProperty.ID = Guid.NewGuid().ToString();
            useProperty.CarUsePropertyName = this.txtName.Text.Trim();
            useProperty.Insert();
            Bind();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (this.lstUseProperty.SelectedItem != null)
            {
                CarUseProperty useProperty = new CarUseProperty();
                useProperty.DeleteWithCondition(" CarUsePropertyName='" + this.lstUseProperty.SelectedItem.ToString() + "'");
                Bind();
            }
            else
            {
                MessageHelper.ShowInfo("请选择要删除的记录！");
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmUsePropertySet_Load(object sender, EventArgs e)
        {
            Bind();
        }

    }
}
